import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

class Student{
    String name;
    int age;
    public Student(String name, int age){
        this.name = name;
        this.age = age;
        System.out.println("name: " + name + ", age: " + age);
    }
    public Student(){
        System.out.println("...");
    }
}
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //获取类对象
        Class<?> c1 = Class.forName("Student");
        //通过反射创建实例
        Student s1 = (Student) c1.newInstance();


        Class<?> c2 = Class.forName("Student");
        //获取参数匹配的私有构造方法
        Constructor<?> constructor = c2.getDeclaredConstructor(String.class,int.class);
        //设置允许
        constructor.setAccessible(true);
        //创建实例
        Student s2 = (Student) constructor.newInstance("kzf",11);

    }
}
